﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Default.master" AutoEventWireup="true" CodeBehind="Article.aspx.cs" Inherits="ecommerceSample.ArticlePage" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ecommerceSample %>" 
        ProviderName="<%$ ConnectionStrings:ecommerceSample.ProviderName %>"             
        SelectCommand="SELECT * FROM Articles INNER JOIN Categories ON Articles.CategoryId = Categories.CategoryId INNER JOIN aspnet_Users ON Articles.UserId = aspnet_Users.UserId WHERE Articles.ArticleId=@id  ORDER BY Date DESC ">
        <SelectParameters>
                <asp:QueryStringParameter Name="id" QueryStringField="id" />
            </SelectParameters>
        </asp:SqlDataSource>
    <asp:FormView ID="FormView1" runat="server" DataKeyNames="ArticleId" DataSourceID="SqlDataSource1" >
        <ItemTemplate>               
            <div class="article-category">
            <a href="/Category.aspx?id=<%# Eval("CategoryId") %>"><%# Eval("Name") %></a>
            </div>
        <hr />
        <div class="article-main-title"><big>
            <a href="/User/Article.aspx?id=<%# Eval("ArticleId") %>"><%# Eval("Title") %></a></big>
        </div>    
        <div class="article-data">
            <small>Posteado por: <big><a href="/User/User.aspx?id=<%# Eval("UserId") %>"><%# Eval("UserName") %></a></big>
             -  <%# Eval("Date") %> </small>
            </div> 
        <div class="article-main-image">
            <img class="small-images" alt="image" src="<%# Eval("Image") %>" width="200px"/>                                 
            </div>
         <div class="article-text">  
            <%# Eval("Text")%>     
            </div>                        
        </ItemTemplate>     
    </asp:FormView>
    <br />
    <!--COMMENTS GRID-->
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
                    ConnectionString="<%$ ConnectionStrings:ecommerceSample %>" 
                    ProviderName="<%$ ConnectionStrings:ecommerceSample.ProviderName %>"             
                    
        SelectCommand="SELECT * FROM Comments INNER JOIN aspnet_Users ON Comments.UserId = aspnet_Users.UserId WHERE Comments.ArticleId=@id  ORDER BY Date DESC" 
        InsertCommand="INSERT INTO Comments(Comment, ArticleId, UserId, Date) VALUES (@comment, @article, @user , @date)" 
        oninserted="SqlDataSource2_Inserted">

        <InsertParameters>
            <asp:Parameter Name="comment" />
            <asp:Parameter Name="article" />
            <asp:Parameter Name="user" />
            <asp:Parameter Name="date" />
        </InsertParameters>

        <SelectParameters>
                <asp:QueryStringParameter Name="id" QueryStringField="id" />
            </SelectParameters>
                </asp:SqlDataSource>   
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                    DataKeyNames="ArticleId" DataSourceID="SqlDataSource2" PageSize="5" BorderWidth="0px" >
                    <Columns>
                        <asp:TemplateField ItemStyle-BorderWidth="0px" 
                            HeaderText="Comentarios"
                            HeaderStyle-CssClass="template-title">
                            <ItemTemplate>
                            <asp:Table ID="Table1" runat="server">
                                    <asp:TableRow ID="TableRow1" runat="server">
                                        <asp:TableCell ID="TableCell1" runat="server" >
                                            <a href="/User/User.aspx?id=<%# Eval("UserId") %>"><img class="small-images" alt="image" src="/Images/Users/admin.jpg" width="50px"/></a>
                                        </asp:TableCell>
                                        <asp:TableCell ID="TableCell2" runat="server" CssClass="text-content">                                            
                                            <hr />
                                            <small>
                                                <div class="article-grey">Posteado por: <big><a href="/User/User.aspx?id=<%# Eval("UserId") %>"><%# Eval("UserName") %></a></big>  -  <%# Eval("Date") %></div>
                                            </small>
                                            <br />    
                                            <%# Eval("Comment")%>                                 
                                        </asp:TableCell>
                                    </asp:TableRow>
                                </asp:Table>
                            </ItemTemplate>
                        </asp:TemplateField>
                    </Columns>
                    <HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle"/>
                    <PagerStyle HorizontalAlign="Center" VerticalAlign="Top" BorderColor="White"/>
                </asp:GridView>                 
    <br />
    <asp:Button ID="btnAddComent" runat="server" Text="Añadir Comentario" 
        onclick="btnAddComent_Click" />
    <asp:Panel ID="Panel1" runat="server" Visible="False">
    <table>
                <tr>
                    <td>
                        <asp:TextBox ID="txtComent" runat="server" TextMode="MultiLine" Height="94px" 
                            Width="374px" Enabled="False"></asp:TextBox> 
                     </td>
                </tr>
                <tr>
                    <td>
                    <table>
                    <tr>
                    <td>
                        <asp:Button ID="btnAcept" runat="server" Text="Aceptar" Enabled="False" />
                    </td>
                    <td>
                    <asp:Button ID="btnCancel" runat="server" Text="Cancelar" Enabled="False"  />
                    </td>
                    </tr>
                    </table>
                    </td>
                </tr>
                 </table>    
    </asp:Panel>

</asp:Content>